﻿
using System;

namespace Stack
{
    public class Solution
    {
        //判断{[()]}
        public bool isVaild(string str)
        {
            System.Collections.Stack stack = new System.Collections.Stack();

            for (int i = 0; i < str.Length; i++)
            {
                string c = str[i].ToString();
                if (c.Equals("{") || c.Equals("[") || c.Equals("("))
                    stack.Push(c);
                else
                {
                    if (stack.Count == 0)
                        return false;
                    string topChar = stack.Pop().ToString();
                    if (c.Equals(")") && !topChar.Equals("("))
                        return false;
                    if (c.Equals("]") && !topChar.Equals("["))
                        return false;
                    if (c.Equals("}") && !topChar.Equals("{"))
                        return false;
                }
            }
            return stack.Count == 0;
        }
    }
}
